Skip to content

chore: add checks for schema changes#1992

Open
mentonin wants to merge 4 commits into
kernelci:mainfrom
profusion:georg/fix/schema-CI
Open

chore: add checks for schema changes#1992
mentonin wants to merge 4 commits into
kernelci:mainfrom
profusion:georg/fix/schema-CI

Conversation

@mentonin

Copy link
Copy Markdown
Contributor

Summary

This PR adds a pre-commit hook to check that backend/schema.yml is up-to-date with python manage.py spectacular.

It also adds all pre-commit checks to the CI workflow, replacing duplicated linting/format specifications.

Related Issues

mentonin added 2 commits July 14, 2026 23:06
Signed-off-by: Luiz Georg <luiz.georg@profusion.mobi>
This removes code duplication and makes the CI checks
consistent with the development environment.

Signed-off-by: Luiz Georg <luiz.georg@profusion.mobi>
@alanpeixinho

Copy link
Copy Markdown
Contributor

@mentonin are we dropping the removal of the schema.yml from versioning?

@tales-aparecida

Copy link
Copy Markdown

how come the CI checks are empty?

Comment thread .github/workflows/ci.yaml Outdated
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont we need to setup node (and pnpm) to be able to run the frontend linters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Pre-commit is able to setup isolated environments, including for node, but we are not using that for the frontend checks

Comment thread .github/workflows/ci.yaml
path: ./dashboard/node_modules

- name: Install pnpm
uses: pnpm/action-setup@v4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be needed on pre-commit run?

Comment thread .github/workflows/ci.yaml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using the old task name here

Comment thread .github/workflows/ci.yaml Outdated
Comment thread .github/workflows/ci.yaml Outdated
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better to reuse setup-backend
uses: ./.github/actions/setup-backend

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need poetry and dependencies, as pre-commit should use its own environment for running tests

Comment thread .github/workflows/ci.yaml Outdated
CI: true

jobs:
pre-commit-checks:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth to include timeout just in case

@alanpeixinho

Copy link
Copy Markdown
Contributor

how come the CI checks are empty?

@mentonin we need to include

how come the CI checks are empty?

I believe the CI checks are tracking code changes only (backend or frontend). Is it correct @mentonin?

@alanpeixinho

Copy link
Copy Markdown
Contributor

how come the CI checks are empty?

@mentonin we need to include

how come the CI checks are empty?

I believe the CI checks are tracking code changes only (backend or frontend). Is it correct @mentonin?

My bad, the changes were for pre-commit only.

mentonin added 2 commits July 20, 2026 10:14
Signed-off-by: Luiz Georg <luiz.georg@profusion.mobi>
Signed-off-by: Luiz Georg <luiz.georg@profusion.mobi>
@mentonin
mentonin force-pushed the georg/fix/schema-CI branch from 7ee4186 to edd0c86 Compare July 20, 2026 13:34

@alanpeixinho alanpeixinho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread .pre-commit-config.yaml
Comment on lines +78 to +98
- id: api-schema
name: API schema is up-to-date
entry: |
python -c '
import os, subprocess, sys;
os.chdir("backend")
subprocess.run(["poetry", "install"], capture_output=True)
spectacular = subprocess.run(["poetry", "run", "python", "manage.py", "spectacular"], capture_output=True, text=True)
new_schema = spectacular.stdout
with open("schema.yml") as f:
old_schema = f.read()
if new_schema != old_schema:
print("Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it")
sys.exit(1)
'
files: 'backend/(.*\.py|schema.yml)'
pass_filenames: false
language: python
language_version: '3.12'
additional_dependencies: [poetry]
stages: [pre-commit]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use python+subprocess instead of sh?

Suggested change
- id: api-schema
name: API schema is up-to-date
entry: |
python -c '
import os, subprocess, sys;
os.chdir("backend")
subprocess.run(["poetry", "install"], capture_output=True)
spectacular = subprocess.run(["poetry", "run", "python", "manage.py", "spectacular"], capture_output=True, text=True)
new_schema = spectacular.stdout
with open("schema.yml") as f:
old_schema = f.read()
if new_schema != old_schema:
print("Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it")
sys.exit(1)
'
files: 'backend/(.*\.py|schema.yml)'
pass_filenames: false
language: python
language_version: '3.12'
additional_dependencies: [poetry]
stages: [pre-commit]
- id: api-schema
name: API schema is up-to-date
entry: |
bash -c '
cd backend || exit 1
poetry install --quiet
NEW_SCHEMA=$(poetry run python manage.py spectacular)
OLD_SCHEMA=$(cat schema.yml 2>/dev/null)
if [ "$NEW_SCHEMA" != "$OLD_SCHEMA" ]; then
echo "Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it"
exit 1
fi
'
files: '^backend/(.*\.py|schema\.yml)$'
pass_filenames: false
language: system
stages: [pre-commit]

-- Assisted-by: Gemini

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also warned about poetry install --quiet causing commits to become slow, but I doubt it's a problem

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, it suggested using --validate --fail-on-warn instead of diffing the schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce OpenAPI schema updates in CI

3 participants